home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-21 / just1v12.zip / JUSTONE.ASM < prev    next >
Assembly Source File  |  1991-07-25  |  5KB  |  178 lines

  1. ;----------------------------------------------------------------------------
  2. ; Module:    justone.asm
  3. ; Author:    David Sparks
  4. ; Revision:    07/15/91    Version 2.0
  5. ; Description:
  6. ;
  7. ; This program is a DESQView Shared Program to prevent multiple
  8. ; instances of the same program from running simultaneously.
  9. ;
  10. ; (c) Copyright 1991 Heartsong Productions
  11. ;----------------------------------------------------------------------------
  12.  
  13.     INCLUDE    DVAPI.INC
  14.  
  15.     .MODEL    TINY
  16.  
  17.     assume    ds:NOTHING,es:NOTHING,ss:NOTHING
  18.  
  19. DV_LEVEL    EQU    0200h        ;Ver 2.00
  20.  
  21.     .CODE
  22.     ORG    0
  23. ;----------------------------------------------------------------------------
  24. ; Common jump for entry and exit code
  25. ;----------------------------------------------------------------------------
  26.  
  27. JustOne        PROC    FAR
  28.     jcxz    Entry
  29.  
  30. ;----------------------------------------------------------------------------
  31. ; This is the exit code
  32. ;----------------------------------------------------------------------------
  33.  
  34.     ret
  35.  
  36. ;----------------------------------------------------------------------------
  37. ; This is the entry code
  38. ;----------------------------------------------------------------------------
  39.  
  40. Entry:
  41.     cld                ;direction flag forward
  42.     mov    bp,sp            ;set up stack frame
  43.  
  44. ;----------------------------------------------------------------------------
  45. ; check DESQView API level
  46. ;----------------------------------------------------------------------------
  47.  
  48.     mov    bx,DV_LEVEL        ;set API level
  49.     @CALL    APILEVEL
  50.  
  51. ;----------------------------------------------------------------------------
  52. ; calculate the length of the shared program data
  53. ;----------------------------------------------------------------------------
  54.  
  55.     les    di,8[bp]        ;get pointer to data
  56.     xor    al,al            ;check for null
  57.     mov    cx,4[bp]        ;max. data length
  58.  
  59.     repnz    scasb            ;scan for zero
  60.     mov    bx,4[bp]        ;get data length
  61.     dec    bx            ;-1
  62.     sub    bx,cx            ;calculate length
  63.     jz    BadSemaphore
  64.  
  65. ;----------------------------------------------------------------------------
  66. ; check the semaphore
  67. ;----------------------------------------------------------------------------
  68.  
  69.     mov    di,8[bp]        ;get pointer
  70.     mov    cx,bx            ;length to cx
  71.     @CALL    FINDMAIL        ;find mailbox
  72.     test    bx,bx            ;check status
  73.     jnz    OnlyOne            ;already exists
  74.  
  75. ;----------------------------------------------------------------------------
  76. ; set our mailbox name to the semaphore name
  77. ;----------------------------------------------------------------------------
  78.  
  79.     push    es            ;pointer to semaphore name
  80.     push    di
  81.     xor    dx,dx
  82.     push    dx            ;length
  83.     push    cx
  84.     @SEND    SETNAME,MAILME
  85.  
  86. ;----------------------------------------------------------------------------
  87. ; everything is OK.
  88. ;----------------------------------------------------------------------------
  89.  
  90.     mov    sp,bp            ;restore stack ptr
  91.     clc                ;clear carry flag
  92.     ret    12
  93.  
  94. ;----------------------------------------------------------------------------
  95. ; OnlyOne
  96. ;----------------------------------------------------------------------------
  97.  
  98. OnlyOne:
  99.     lea    di,OnlyOneMsg        ;point to error message
  100.     mov    bx,OnlyOneMsgSize    ;get size of message
  101.     call    DispError        ;display message
  102.  
  103. ;----------------------------------------------------------------------------
  104. ; Be sure that this task continues to run
  105. ;----------------------------------------------------------------------------
  106.  
  107.     mov    [MgrCtrl],87h        ;allow to run in background
  108.     lea    di,MgrStream        ;point to stream
  109.     push    cs            ;save ptr on stack
  110.     push    di
  111.     xor    dx,dx            ;MSB of length
  112.     push    dx
  113.         mov     cx,MgrStreamLen        ;LSB of length
  114.     push    cx
  115.         @SEND    WRITE,ME        ;send message to this window
  116.  
  117. ;----------------------------------------------------------------------------
  118. ; Move original instance to foreground
  119. ;----------------------------------------------------------------------------
  120.  
  121.     mov    [MgrCtrl],0c1h        ;move to foreground
  122.     push    cs            ;save ptr on stack
  123.     push    di
  124.     push    dx            ;save length on stack
  125.     push    cx
  126.     xor    si,si
  127.     @SEND    WRITE,DSSI        ;send to original task
  128.     jmp    ErrorExit
  129.  
  130. ;----------------------------------------------------------------------------
  131. ; No semaphore name
  132. ;----------------------------------------------------------------------------
  133.  
  134. BadSemaphore:
  135.     lea    di,NoSema4Msg        ;point to error message
  136.     mov    bx,NoSema4MsgSize    ;get size of message
  137.     call    DispError        ;display error message
  138.     mov    sp,bp            ;restore stack
  139.  
  140. ErrorExit:
  141.     xor    ax,ax            ;tell DV not to display message
  142.     stc                ;indicate failure
  143.     ret    12
  144. JustOne        ENDP
  145.  
  146.  
  147. ;----------------------------------------------------------------------------
  148. ; DispError
  149. ;
  150. ; Entry:
  151. ;    DI -> error message
  152. ;    DX = message length
  153. ;----------------------------------------------------------------------------
  154.  
  155. DispError    PROC    NEAR
  156.     mov    ax,cs            ;get code seg
  157.     mov    es,ax            ;point to code seg
  158.     mov    dx,ss            ;get target handle
  159.     xor    cx,cx            ;let DV decide window size
  160.     @CALL    DISPEROR
  161.     ret
  162. DispError    ENDP
  163.  
  164. ;----------------------------------------------------------------------------
  165. ; Data
  166. ;----------------------------------------------------------------------------
  167.  
  168. NoSema4Msg    db    "Semaphore name required in shared data field"
  169. NoSema4MsgSize    equ    $-NoSema4Msg
  170. OnlyOneMsg    db    "Only one instance of this program allowed.  Switching to original instance..."
  171. OnlyOneMsgSize    equ    $-OnlyOneMsg
  172. MgrStream    db    1Bh,10h,1,0    ;stream header
  173. MgrCtrl        db    0        ;command byte goes here
  174. MgrStreamLen equ        $-MgrStream
  175.  
  176.     END
  177.  
  178.